package com.yuezhu.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuezhu.R;
import com.yuezhu.global.ParallaxSwipeBackActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MoreAppActivity extends ParallaxSwipeBackActivity {
    @InjectView(R.id.bottom_left)
    View bottom_left;
    @InjectView(R.id.bottom_middle)
    View bottom_middle;
    @InjectView(R.id.bottom_right)
    View bottom_right;
    @InjectView(R.id.iv_bottome_left)
    ImageView ivBottomeLeft;
    @InjectView(R.id.iv_bottome_middle)
    ImageView ivBottomeMiddle;
    @InjectView(R.id.iv_bottome_right)
    ImageView ivBottomeRight;
    @InjectView(R.id.iv_menu)
    ImageView ivMenu;
    @InjectView(R.id.tv_title)
    TextView tvTitle;
    @InjectView(R.id.iv_quite)
    ImageView ivQuite;
    @InjectView(R.id.tv_version)
    TextView tvVersion;
    @InjectView(R.id.webView)
    WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more_app);
        ButterKnife.inject(this);
        initView();
        setListeners();
    }


    @Override
    protected void initView() {
        ivMenu.setImageResource(R.drawable.zhuoyun);
        tvTitle.setText("更多专业应用");
        ivQuite.setVisibility(View.GONE);
        ivBottomeLeft.setVisibility(View.GONE);
        bottom_left.setVisibility(View.GONE);
        ivBottomeMiddle.setVisibility(View.VISIBLE);
        bottom_middle.setVisibility(View.VISIBLE);
        ivBottomeRight.setVisibility(View.GONE);
        bottom_right.setVisibility(View.GONE);
        ivBottomeMiddle.setImageResource(R.drawable.back);
        //应用的填充

//        gridview1.setAdapter(new MoreAppAdapter(this, 1));
//        gridview2.setAdapter(new MoreAppAdapter(this, 2));
//        gridview3.setAdapter(new MoreAppAdapter(this, 3));
        initWebView();
    }

    private void initWebView() {
        WebSettings settings = mWebView.getSettings();
        //支持javascript
        settings.setJavaScriptEnabled(true);
        // 设置可以支持缩放
        settings.setSupportZoom(true);
        // 设置出现缩放工具
//        settings.setBuiltInZoomControls(true);
        //扩大比例的缩放
        settings.setUseWideViewPort(true);
        //自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);
//        mWebView.addJavascriptInterface(object, name)
        String url="http://www.zcloud-online.com/AppService/AppsList?typeId=0";
        mWebView.loadUrl(url);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                //在此处显示加载失败页面
                //   view.loadUrl("https://www.baidu.com");

            }

        });
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack(); //goBack()表示返回WebView的上一页面
            return true;
        } else {
            finish();
        }
        return false;
    }
    @Override
    protected void setListeners() {
        super.setListeners();
        ivBottomeMiddle.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.iv_bottome_middle:
                finish();
                break;
        }
    }
}

